package com.demo.dlxOne;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;

/**
 * @Author: lkz
 * @Title: DlxTwoProMsg
 * @Description: TODO
 * @Date: 2023/10/16 14:41
 */
@RestController
@Slf4j
public class DlxOneProMsg {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMsg")
    public void sendMsg(){
        //消息属性
//        MessageProperties messageProperties=new MessageProperties();
//        //设置单条消息的过期时间，单位为毫秒，数据类型为字符串
//        messageProperties.setExpiration("15000");
        Message message= MessageBuilder.withBody("消息延迟发送死信队列".getBytes())
                .setMessageId(UUID.randomUUID().toString())
              //  .andProperties(messageProperties)
                .build();
        for(int i=0;i<5;i++){
            rabbitTemplate.convertAndSend("dlx.one.normalExchange","order",message);
            log.info("消息发送完毕：发送时间为：{}",new Date());
        }
//        rabbitTemplate.convertAndSend("dlx.one.normalExchange","order",message);
//        log.info("消息发送完毕：发送时间为：{}",new Date());
    }

}
